#include "CDevice.h"

//________________________________________________________________________
CDevice::CDevice(QextPortInfo info, int simulation)
{
    m_simulation = simulation;
    m_fileSystem = NULL;

    m_hardwareFacade = new CHardwareFacade();
    m_hardwareFacade->SetInitParameters(info, simulation);
    m_deviceType = m_hardwareFacade->CheckConnectionAndType( );

    if (m_deviceType == NOTHING_FOUND)
        return;

    m_deviceNumber = -1;
//   m_fileSystem = new CFileSystem ( m_hardwareFacadeList->GetParameters( ) );
}

//________________________________________________________________________
CDevice::CDevice(const CDevice& device)
{
    if (device.m_hardwareFacade!=NULL)
    {
        m_hardwareFacade = new CHardwareFacade(*device.m_hardwareFacade);
    }
    else
    {
        m_hardwareFacade = NULL;
    }

    if (device.m_fileSystem!=NULL)
    {
        m_fileSystem = new CFileSystem(*device.m_fileSystem);
    }
    else
    {
        m_fileSystem = NULL;
    }

    m_simulation = device.m_simulation;
    m_deviceType = device.m_deviceType;
    m_deviceNumber = device.m_deviceNumber;
}

//________________________________________________________________________
CDevice::~CDevice()
{
    if (m_hardwareFacade!=NULL)
        m_hardwareFacade->DisconnectDevice();

    if (m_hardwareFacade!=NULL)
        delete m_hardwareFacade;

    if (m_fileSystem!=NULL)
        delete m_fileSystem;
}

//________________________________________________________________________
void CDevice::setDeviceNumber (int number)
{
    m_deviceNumber = number;
    if (m_hardwareFacade!=NULL)
        m_hardwareFacade->setDeviceNumber(number);
}

//________________________________________________________________________
int CDevice::isSimulated ( void )
{
    return m_simulation;
}

//________________________________________________________________________
int CDevice::getDeviceType (  )
{
    return m_deviceType;
}

//________________________________________________________________________
CFileSystem* CDevice::getFileSystem ( void )
{
    return m_fileSystem;
}

//________________________________________________________________________
CHardwareFacade* CDevice::getHardwareFacade ( void )
{
    return m_hardwareFacade;
}

//________________________________________________________________________
int CDevice::CreateFileSystem ( CHardwareParams *params )
{
    if (params==NULL)
        return -1;

    m_fileSystem = new CFileSystem ( m_hardwareFacade->GetParameters( ) );
    return 0;
}

//________________________________________________________________________
void CDevice::releaseHardwareFacade ( void )
{
    if (m_hardwareFacade!=NULL)
    {
        m_hardwareFacade->DisconnectDevice();
        delete m_hardwareFacade;
        m_hardwareFacade = NULL;
    }

}
